package imdbfolder.data;

import java.io.Serializable;
import java.security.InvalidParameterException;

public class Movie implements Serializable {

    private static final long serialVersionUID = 1L;

    private String fileName;

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    private String type = "";

    private String imdbId = "";

    private String title = "";

    private int year;

    private float score;

    private String genres = "";
    
    private String actors = "";
    
    private String directors = "";

    private int runtime;

    private String plotSummary = "";

    private String numVotes;

    public String getGenres() {
        return genres;
    }

    public void setGenres(String genres) {
        this.genres = genres;
    }
    
    public String getActors() {
        return actors;
    }

    public void setActors(String actors) {
        this.actors = actors;
    }
    
    public String getDirectors() {
        return directors;
    }

    public void setDirectors(String directors) {
        this.directors = directors;
    }

    public String getImdbId() {
        return imdbId;
    }

    public void setImdbId(String imdbId) {
        if (imdbId.length() != 9) {
            throw new InvalidParameterException("IMDB ID should be 9 chars");
        }

        this.imdbId = imdbId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String naam) {
        this.title = naam;
    }

    public int getRuntime() {
        return runtime;
    }

    public void setRuntime(int runtime) {
        this.runtime = runtime;
    }

    public float getScore() {
        return score;
    }

    public void setScore(float score) {
        this.score = score;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Object[] getTableData() {
        Object[] data = { type, title, score, genres, directors, actors, runtime };
        return data;
    }

    public String getPlotSummary() {
        return plotSummary;
    }

    public void setPlotSummary(String plotSummary) {
        this.plotSummary = plotSummary;
    }

    public String getNumVotes() {
        return numVotes;
    }

    public void setNumVotes(String numVotes) {
        this.numVotes = numVotes;
    }

    public String getInfoText() {
        return "Number of votes: " + numVotes + "\nPlot Summary: " + getPlotSummary();
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getYear() {
        return year;
    }

    @Override
    public boolean equals(Object other) {
        if (other == null) {
            return false;
        }

        return imdbId.equals(((Movie) other).getImdbId());
    }

    public String getImdbUrl() {
        return "http://www.imdb.com/title/" + imdbId + "/";
    }

    public void setFetchedInfo(boolean fetchedInfo) {
        this.fetchedInfo = fetchedInfo;
    }

    public boolean isFetchedInfo() {
        return fetchedInfo;
    }

    private boolean fetchedInfo = false;

    public boolean matchesText(String text) {
        return title.toLowerCase().indexOf(text) != -1 || 
        		genres.toLowerCase().indexOf(text) != -1 || 
        		plotSummary.toLowerCase().indexOf(text) != -1 || 
        		actors.toLowerCase().indexOf(text) != -1 || 
        		directors.toLowerCase().indexOf(text) != -1;
    }

}
